home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / examples / menufrob.lsp < prev    next >
Encoding:
Text File  |  1991-10-06  |  9.3 KB  |  223 lines

  1. ; -*-Lisp-*-
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ; File:         menufrob.lsp
  5. ; RCS:          $Header: menufrob.lsp,v 1.1 91/10/05 21:36:58 mayer Exp $
  6. ; Description:  Dynamically altering XmCreateSimple...() created menus...
  7. ; Author:       Niels Mayer, HPLabs
  8. ; Created:      Sat Oct  5 21:34:39 1991
  9. ; Modified:     Sat Oct  5 21:36:00 1991 (Niels Mayer) mayer@hplnpm
  10. ; Language:     Lisp
  11. ; Package:      N/A
  12. ; Status:       X11r5 contrib tape release
  13. ;
  14. ; WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. ; XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. ;
  17. ; Permission to use, copy, modify, distribute, and sell this software and its
  18. ; documentation for any purpose is hereby granted without fee, provided that
  19. ; the above copyright notice appear in all copies and that both that
  20. ; copyright notice and this permission notice appear in supporting
  21. ; documentation, and that the name of Hewlett-Packard and Niels Mayer not be
  22. ; used in advertising or publicity pertaining to distribution of the software
  23. ; without specific, written prior permission.  Hewlett-Packard and Niels Mayer
  24. ; makes no representations about the suitability of this software for any
  25. ; purpose.  It is provided "as is" without express or implied warranty.
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27.  
  28. ; To: OSF/Motif source licencee mailing List <motif-talk@osf.org>
  29. ; Subject: Re: XmCreateSimpleWhatever 
  30. ; In-Reply-To: Your message of Thu, 05 Sep 91 08:33:01 -0600
  31. ; Organization: Hewlett-Packard Labs, Software & Systems Lab, Palo Alto, CA.
  32. ; X-Mailer: mh6.7
  33. ; Date: Thu, 05 Sep 91 16:28:57 -0700
  34. ; Message-Id: <25898.684113337@hplnpm.hpl.hp.com>
  35. ; From: "Niels P. Mayer" <mayer@hplnpm.hpl.hp.com>
  36. ; >    May be your example is incomplete or I was not clear enough.
  37. ; >    The problems I see are not at *creation* time - any tool can deal
  38. ; >    with the creation.
  39. ; >    The problems I see are with dynamics. If I use a "Simple" style
  40. ; >    constructor, I use one set of controls. But I can't use the same
  41. ; >    set of controls to alter (change, modify) created object(s).
  42. ; >    I could use a different set (RowColumn controls in case of menus),
  43. ; >    but how do I tell that to a generic tool ? Do I have to describe
  44. ; >    such an objectt twice: intialization controls versus runtime controls?
  45. ; >
  46. ; >    Note that my tools typically rely on XtGetResourceLists from any object
  47. ; >    they control - which does not quite work with XmCreateSimple ....
  48. ; For your case, I think the answer is yes, you have to describe the object
  49. ; twice, and write lots of kludges because many composite/compound widgets in
  50. ; Motif do not offer a consistent view of the world based on resources alone.
  51. ; The resources-are-everything assumption may have been sufficient for Xaw or
  52. ; Xw... but, IMHO, they are an oversimplification when dealing with Motif.
  53. ; Thus, you may want to punt on XmCreateSimple*() routines in some "generic
  54. ; tools" especially ones that rely entirely on resources, such as WCL, or
  55. ; ones that provide a language expressive enough to only cover widget
  56. ; creation and static bindings (UIL, WCL).
  57. ; As I mentioned, the XmCreateSimple*() routines are oriented towards
  58. ; creation of STATIC {pulldown,popup,option} menus, radioboxes, and menubars.
  59. ; For menus which change dynamically at runtime, you may be better off using
  60. ; the "traditional" menu creation routines.
  61. ; Perhaps I don't understand what you're getting at here -- you will use the
  62. ; traditional runtime controls to do dynamic changes, the main difference is
  63. ; that you cannot directly access the children widgets created by
  64. ; XmCreateSimple*(). The other difference is that the
  65. ; XmCreateSimple*()-specific resources are CREATE-TIME only resources. The
  66. ; arrays of button types, button names, accelerator texts, accelerators, etc
  67. ; are indexed-through at create-time and the appropriate values from each
  68. ; array are passed on to each child created by the XmCreateSimple*()
  69. ; routines. To make any dynamic changes, you'll have to access the child
  70. ; widgets directly using traditional means (many of which lie outside the
  71. ; language-expressivity of WCL/UIL).
  72. ; However, that's not to say that you cannot do dynamic changes to a menu
  73. ; that is created via, say, XmCreateSimplePulldownMenu(). With respect to WCL
  74. ; and other resource-based tools, you'll need to look up the desired button
  75. ; with resource name "button_<#>" where 0 <= <#> < XmNbuttonCount.  When
  76. ; programming in C, or with WINTERP, you'll need to access the children of
  77. ; the simple menu via XmRowColumn resources XmNchildren/XmNnumChildren.
  78. ; For example, to grey-out the "Save" button within the menu-code I posted
  79. ; yesterday, I just evaluate the following WINTERP expression:
  80. ;     (send (aref (send pulldown_w :get_children) 3) :set_values
  81. ;           :XMN_SENSITIVE nil)
  82. ; And the button will immediately change to insensitive (aka greyed-out).
  83. ; The code above just accesses the child widget at index 3 retrieved from the
  84. ; XmNchildren resource (:get_children) of pulldown_w. (pulldown_w is bound to
  85. ; a row/col instance created via XmCreateSimplePulldownMenu()). Once the
  86. ; child widget is accessed, the code sends a message to do an XtSetValues()
  87. ; (send ... :set_values ...) on resource XmNsensitive (:XMN_SENSITIVE),
  88. ; setting it to FALSE (nil).
  89. ; One can just as easily go through and dynamically change the resources
  90. ; XmNlabelString, XmNmnemonic, XmNacceleratorText, and XmNaccelerators on all
  91. ; the widgets contained in the pulldown widget bound to 'pulldown_w' by
  92. ; evaluating the following code:
  93. ; (let*                    
  94. ;     (;; declare, bind, initialize local variables
  95. ;      (children    (send pulldown_w :get_children)) ;retrieve XmNchildren array
  96. ;      (length    (length children))
  97. ;      )
  98. ;   ;; loop through children
  99. ;   (do
  100. ;    ;; Declare variables local to do loop, initialize, specify incrementor
  101. ;    ((i 0 (1+ i)))
  102. ;    ;; Test for loop termination
  103. ;    ((<= length i)            
  104. ;     )
  105. ;    ;; Loop body
  106. ;    ;; Note: in the code below,
  107. ;    ;; (format nil "...~A..." i) is similar to the C code
  108. ;    ;; sprintf(buf, "...%d..." i)
  109. ;    (send (aref children i) :set_values    ;XtSetValues() on i-th child
  110. ;      :XMN_LABEL_STRING    (format nil "menu: ~A" i)
  111. ;      :XMN_MNEMONIC        (format nil "~A" i)
  112. ;      :XMN_ACCELERATOR_TEXT    (format nil "^~A" i)
  113. ;      :XMN_ACCELERATORS      (format nil "Ctrl<Key>~A: Lisp(print ~A)" i i)
  114. ;      )
  115. ;    )                    ;end-do
  116. ;   )                    ;end-let*
  117. ; This will change the menu to look like
  118. ;         menu: _0_    ^0
  119. ;         menu: _1_    ^1
  120. ;         menu: _2_    ^2
  121. ;         menu: _3_    ^3
  122. ;         menu: _4_    ^4
  123. ;         menu: _5_    ^5
  124. ; (The only problem with the above code is that the accelerators do not get
  125. ; automatically installed on other widgets. This needs to be done with
  126. ; XtInstallAccelerators()...)
  127.  
  128.  
  129. (load "rc-shell")
  130.  
  131. (setq menubar_w
  132.       (send XM_ROW_COLUMN_WIDGET_CLASS :new :managed :simple_menu_bar
  133.         "menubar" rc_w
  134.         :XMN_BUTTON_COUNT 5        ;create five cascadebuttons in menubar
  135.         :XMN_BUTTONS
  136.         #("Files" "Edit" "Fold" "Spindle" "Mutilate")
  137.         :XMN_BUTTON_MNEMONICS
  138.         #(#\F     #\E    #\o    #\S       #\M)
  139.         ))
  140.  
  141. (setq pulldown_w
  142.       (send XM_ROW_COLUMN_WIDGET_CLASS :new :simple_pulldown_menu
  143.         "pulldown" menubar_w
  144.         :XMN_POST_FROM_BUTTON 0    ;post pulldown from menubar's "Files"
  145.         :XMN_BUTTON_COUNT 5        ;create five buttons in this pulldown
  146.         :XMN_BUTTONS
  147.             #("Quit" "Open" "Open in New Window" "Save" "Save As")
  148.         :XMN_BUTTON_MNEMONICS
  149.             #(#\Q    #\O    #\N                  #\S    #\A)
  150.         :XMN_BUTTON_MNEMONIC_CHAR_SETS
  151.             #("" "" "ISO8859-1" "ISO8859-1" "ISO8859-1")
  152.         :XMN_BUTTON_ACCELERATORS
  153.             #("Ctrl<Key>C" "Ctrl<Key>F" "Ctrl<Key>O" "Ctrl<Key>S" "Ctrl<Key>W")
  154.         :XMN_BUTTON_ACCELERATOR_TEXT
  155.             #("^C" "^F" "^O" "^S" "^W")
  156.         :XMN_BUTTON_TYPE
  157.             #(:PUSHBUTTON :PUSHBUTTON :PUSHBUTTON :PUSHBUTTON :PUSHBUTTON)
  158.         ))
  159.  
  160.  
  161. (send pulldown_w :add_callback :XMN_ENTRY_CALLBACK ;use instead of XmNsimpleCallback
  162.       '(CALLBACK_ENTRY_WIDGET)        ;gets bound to widget causing c.b.
  163.       '(
  164.     ;; (send CALLBACK_ENTRY_WIDGET :name)==XtName() returns "button_<#>"
  165.     ;; where <#> is 0 ... (:XMN_BUTTON_COUNT - 1).
  166.     ;; we use 'read' to return the FIXNUM <#> after truncating the
  167.     ;; 7 chars "button_" from the front of the string.
  168.     (case (read (make-string-input-stream
  169.              (send CALLBACK_ENTRY_WIDGET :name) 7))
  170.           (0 (format T "Quit Function Called\n"))
  171.           (1 (format T "Open Function Called\n"))
  172.           (2 (format T "Open in New Window Function Called\n"))
  173.           (3 (format T "Save Function Called\n"))
  174.           (4 (format T "Save As Function Called\n"))
  175.           (T (format T "Error\n")))
  176.     ))
  177.  
  178.  
  179. ;;
  180. ;; do interactive changes
  181. ;;
  182.  
  183. (let*                    
  184.     (;; declare and bind local variables
  185.      (children    (send pulldown_w :get_children)) ;XtGetValues(XmNchildren/XmNnumChildren)
  186.      (length    (length children))
  187.      )
  188.  
  189.   ;; loop through children
  190.   (do
  191.    ;; set up local loop variables and incrementors
  192.    ((i 0 (1+ i)))
  193.    ;; test and return value
  194.    ((<= length i)            
  195.     )
  196.    ;; loop body
  197.    (send (aref children i) :set_values    ;XtSetValues() on i-th child
  198.      :XMN_LABEL_STRING    (format nil "menu: ~A" i)
  199.      :XMN_MNEMONIC        (format nil "~A" i)
  200.      :XMN_ACCELERATOR_TEXT    (format nil "^~A" i)
  201.      :XMN_ACCELERATORS      (format nil "Ctrl<Key>~A: Lisp(print ~A)" i i)
  202.      )
  203.    )                    ;end-do
  204.   )                    ;end-let*
  205.  
  206.  
  207. (send (aref (send pulldown_w :get_children) 3) :set_values
  208.       :XMN_SENSITIVE t)
  209.  
  210. (send (aref (send pulldown_w :get_children) 3) :destroy)
  211.